<template>
  <div class="app-container">
    <el-button
      type="primary"

      @click="addSegment"
    >新增节次
    </el-button
    >
    <!--   -->
    <div class="tips">注：时间不可重合</div>
    <el-table v-loading="loading" :data="tableData">
      <el-table-column label="节次" align="center" prop="name">
      </el-table-column>
      <el-table-column label="节次时间范围" align="center" prop="time">
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="updateSegment(scope.row)"
          >编辑
          </el-button>
          <el-button
            size="mini"
            type="text"
            v-show="scope.$index !== 0"
            @click="moveSegment()"
          >上移
          </el-button>
          <el-button
            size="mini"
            type="text"
            v-show="scope.$index !== tableData.length - 1"
            @click="moveSegment()"
          >下移
          </el-button>
          <el-button size="mini" type="text" @click="deleteSegment(scope.row)"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <editSegment ref="editSegment"></editSegment>
  </div>
</template>

<script>
import editSegment from '@/views/configuration/components/editSegment.vue'

export default {
  name: 'SegmentAllocation',
  data() {
    return {
      tableData: [],
      loading: false
    }
  },
  components: { editSegment },
  mounted() {
    this.getSegmentData()
  },
  methods: {
    async getSegmentData() {
      this.loading = true
      this.tableData = [
        {
          id: 1,
          name: '第一节',
          time: '08:00-08:45'
        },
        {
          id: 2,
          name: '第二节',
          time: '08:00-08:45'
        },
        {
          id: 3,
          name: '第三节',
          time: '08:00-08:45'
        }
      ]
      this.loading = false
    },
    addSegment() {
      this.$refs.editSegment.show()
    },
    updateSegment(data) {
      this.$refs.editSegment.show(data)
    },
    deleteSegment(data) {
      this.$confirm(
        `确定删除【${data.name}】吗？删除后教师将无法在该时段进行考勤操作，且此操作不可撤销！`,
        '删除确认',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消'
        }
      )
        .then(() => {
          console.log('删除成功，刷新数据')
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    moveSegment() {
      // type:1 上移 0 下移
      console.log('移动成功，刷新数据')
    }
  }
}
</script>

<style scoped lang="scss">
.tips {
  margin: 20px 0;
  font-size: 14px;
  color: orange;
}
</style>
